<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div>
        <h3>受控组件</h3>
        <div id="control"></div>
        <h3>非受控组件</h3>
        <div id="uncontrol"></div>
    </div>
	<script src="../build/react.js"></script>
	<script src="../build/react-dom.js"></script>
	<script src="../build/browser.min.js"></script>
    <script type="text/babel">
        /* eslint-disable no-console */
		class ControlledForm extends React.Component {
			constructor(props) {
				super(props)
				this.state = {
					username: ''
				}
				this.handleSubmit = this.handleSubmit.bind(this)
				this.updateUsername = this.updateUsername.bind(this)
			}

			updateUsername(e) {
				this.setState({
					username: e.target.value,
				})
			}

			handleSubmit() {}

			render () {
				return (
					<form onSubmit={this.handleSubmit}>
						<input
							type='text'
							value={this.state.username}
							onChange={this.updateUsername} />
						<button type='submit'>Submit</button>
					</form>
				)
			}
		}
        ReactDOM.render(<ControlledForm />, document.getElementById('control'))
        
		class UnControlledForm extends React.Component {
			constructor(props) {
				super(props)
				this.handleSubmit = this.handleSubmit.bind(this)
			}

			handleSubmit(e) {
				e.preventDefault()
				console.log("Value: ", this.input.value)
			}

			render () {
				return (
					<form onSubmit={this.handleSubmit}>
					<input
                        type='text'
                        ref={(input) => this.input = input} />
					<button type='submit'>Submit</button>
					</form>
				)
			}
		}
        ReactDOM.render(<UnControlledForm />, document.getElementById('uncontrol'))
    </script>
</body>
</html>